package com.foreknow.demo9;

import java.io.*;

public class TestEmployee {
    public static void main(String[] args) {
//        try {
//            FileOutputStream fos = new FileOutputStream("t.ser");
//            ObjectOutputStream oos = new ObjectOutputStream(fos);
//            //向文件中写对象
//            oos.writeObject(new Employee("张三",20,"市场部"));
//            oos.writeObject(new Employee("李四",23,"技术部"));
//            oos.close();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }


        try {
            FileInputStream fis = new FileInputStream("t.ser");
            ObjectInputStream ois = new ObjectInputStream(fis);
            Employee e1 = (Employee) ois.readObject();
            Employee e2 = (Employee) ois.readObject();
            System.out.println(e1.getName());
            System.out.println(e2.getName());

        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}
